package com.dubito.mappers;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.dubito.model.StuAn;

public interface StuAnMapper {

	@Insert("insert into t_stuan values(null,#{name},#{age})")
	public int insertStuAn(StuAn stuAn);
	@Update("update t_stuan set name=#{name},age=#{age} where id=#{id}")
	public int updateStuAn(StuAn stuAn);
	@Delete("delete from t_stuan where id=#{id}")
	public int deleteStuAnById(Integer id);
	@Select("select * from t_stuan where id=#{id}")
	public StuAn getById(Integer id);
	@Select("select * from t_stuan")
	@Results(
			{
				@Result(id=true,column="id",property="id"),
				@Result(column="name",property="name"),
				@Result(column="age",property="age")
			}
	)
	public List<StuAn> findAll();
	
	/**
	 * 一对一查询
	 * @param id
	 * @return
	 */
	@Select("select * from t_stuan where id=#{id}")
	@Results(
			{
				@Result(id=true,column="id",property="id"),
				@Result(column="name",property="name"),
				@Result(column="age",property="age"),
				@Result(column="addressId",property="addressStuAn",one=@One(select="com.dubito.mappers.AddressStuAnMapper.getById"))
			}
	)
	public StuAn selectStuAnWithAddress(Integer id);
	
	@Select("select * from t_stuan where gradeId=#{gradeId}")
	@Results(
			{
				@Result(id=true,column="id",property="id"),
				@Result(column="name",property="name"),
				@Result(column="age",property="age"),
				@Result(column="addressId",property="addressStuAn",one=@One(select="com.dubito.mappers.AddressStuAnMapper.getById"))
			}
	)
	public StuAn selectStuAnWithGrade(Integer id);
	
	@Select("select * from t_stuan where id=#{id}")
	@Results(
			{
				@Result(id=true,column="id",property="id"),
				@Result(column="name",property="name"),
				@Result(column="age",property="age"),
				@Result(column="addressId",property="addressStuAn",one=@One(select="com.dubito.mappers.AddressStuAnMapper.getById")),
				@Result(column="gradeId",property="gradeStuAn",one=@One(select="com.dubito.mappers.GradeStuAnMapper.getById"))
			}
	)
	public StuAn selectStuAnWithAddressAndGrade(Integer id);
}
